package cn.yunbamboos.rest.service.apidoc.helper;

import cn.yunbamboos.rest.service.anno.param.ParamType;
import cn.yunbamboos.rest.service.apidoc.meta.MediaType;
import cn.yunbamboos.rest.service.apidoc.meta.Schema;
import cn.yunbamboos.rest.service.apidoc.meta.schema.ObjectSchema;
import cn.yunbamboos.rest.service.dto.DTO;
import com.alibaba.fastjson2.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;


public class ReadRequestHelper extends ReadObjectHelper {

    private static final Logger logger = LoggerFactory.getLogger(ReadRequestHelper.class);

    private final Class<? extends DTO> in;

    private final MediaType mediaType = new MediaType();

    public ReadRequestHelper(Class<? extends DTO> in){
        this.in = in;
    }

    public void read() {
        ObjectSchema schema = new ObjectSchema("object");
        // 读取所有属性
        logger.info("读取InDTO: {}", in);
        this.readObject(schema, in);

        mediaType.setSchema(schema);
        // 示例
        JSONObject examples = new JSONObject();
        schema.toExample(examples);
        mediaType.setExample(examples.getJSONObject("object"));
    }

    public MediaType getMediaType() {
        return mediaType;
    }

    public Schema getModel(ParamType paramType, Field field){
        return null;
    }
}
